home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group93b.txt
/
000109_icon-group-sender _Thu May 20 01:22:30 1993.msg
< prev
next >
Wrap
Internet Message Format
|
1993-06-16
|
3KB
Received: from owl.CS.Arizona.EDU by cheltenham.cs.arizona.edu; Thu, 20 May 1993 15:41:54 MST
Received: by owl.cs.arizona.edu; Thu, 20 May 1993 15:41:52 MST
Date: 20 May 93 01:22:30 GMT
From: world!ksr!tim@uunet.uu.net (Tim Peters)
Organization: Kendall Square Research Corp.
Subject: Re: A bug? Or a feature?
Message-Id: <26810@ksr.com>
References: <12743@sun13.scri.fsu.edu>
Sender: icon-group-request@cs.arizona.edu
To: icon-group@cs.arizona.edu
Status: R
Errors-To: icon-group-errors@cs.arizona.edu
In article <12743@sun13.scri.fsu.edu> nall@ibm12.scri.fsu.edu (John Nall) writes:
> ...
> The Icon reference manual says (and I quote):
>
> X1 op:= X2
>
> "performs the operation X1 op X2 and assigns the result to X1
>
> All well and good, and by and large it does exactly that. With a
> slight variation, however. To wit: it actually:
>
> "performs the operation X1 op (X2) and assigns the result to X1"
> ^ ^
> ...
> A bug? Or a feature?
A harmless ambiguity <grin>. I'm sure Icon's working as intended here,
but there are many places in the language where a precise description of
the semantics might scare off the manual's primary audience <wink>.
There's another (well, at least one more) ambiguity in the text you
quote, to wit how many times X1 is evaluated. An example to show the
difference:
global i1, i2
procedure main(switch)
i1 := 1
i2 := 2
if *switch > 0 then {
write( "pick() +:= 10" )
pick() +:= 10
} else {
write( "pick() := pick() + 10" )
pick() := pick() + 10
}
write( i1, " ", i2 )
end # procedure main
procedure pick()
static i
initial i := 0
case i +:= 1 of {
1 : return i1
2 : return i2
}
end # procedure pick
If run without arguments, it prints
pick() := pick() + 10
12 2
If run with an argument,
pick() +:= 10
11 2
The point is that the left-hand side is evaluated exactly once in an
augmented assignment, & I'm not sure The Bible ever says that except for
an implication on pg 74 (where it notes that augmented assignment "is
particularly useful for tables [because the table lookup is done only
once]").
Both behaviors (evaluating the LHS once, & evaluating the RHS without
regard to the LHS) are the norm for languages with augmented assignment,
but I think it's been historically rare for language manuals to say so
clearly. For a recent example of one that does, check out the
explanations of augmented assignment in the ISO C standard. It will make
you appreciate the friendly-though-incomplete explanation in the Icon
manual <smile>.
but-agreeing-that-a-pair-of-parens-in-the-text-would-help-clarify-one-
of-the-potential-confusions-ly y'rs - tim
Tim Peters tim@ksr.com
not speaking for Kendall Square Research Corp